Skip to content
This repository has been archived by the owner on Oct 1, 2024. It is now read-only.

Enable/fix test typing #2034

Merged
merged 14 commits into from
Sep 14, 2021
Merged

Enable/fix test typing #2034

merged 14 commits into from
Sep 14, 2021

Conversation

peter-hamilton
Copy link
Contributor

@peter-hamilton peter-hamilton commented Sep 10, 2021

Description

Enable type-checking and fix type errors for a batch of packages.

Changes

  • react-async
    • add missing cancelled property.
    • changed noop() to match expected type.
  • react-bugsnag
    • removed unused ReactPlugin plugin
  • react-form
    • Change return type for mockField to allow for Field<undefined>
    • cast onClick callbacks to any in a test where the event is programmatically triggered.
    • add non-null assertions to controlled Root.find() returns.
    • add missing argument to randomVariants() call
  • react-import-remote
    • Used unsafe type casts to mock parts of the DOM.
  • react-graphql-universal-provider
    • Removed unused variables
      • In one case, eslint disable-next-line no-new was suppressed for a test that with new ApolloLink()
  • react-hooks
    • define argument types for mock functions
    • add non-null assertions to controlled Root.find() returns
  • react-html
    • fix typo nomodule -> noModule
  • react-network
    • Correct function return type.
  • react-router
    • Aligned the types returned by createDefaultHistory and createDefaultLocation. NOTE: These functions aren't used within Quilt so it's not clear how to test the changes.
  • react-server
    • Import saddle-up matcher in src/tests/setup.ts
    • cast Context.body as NodeJS.ReadableStream after createRender is called.
    • Changed MockApp to return null instead of void in order to make it a valid JSX component.
  • react-testing
    • Added missing options: MountOptions argument for mountWithContext being used in e2e.test.tsx. NOTE: It's possible options SHOULD be an optional parameter. If that's the case, .createMount typing should be changed instead.
    • Used hard cast for a case where Node<unknown> was being compared to Element<{}>

Type of change

  • react-testing Patch: Bug (non-breaking change which fixes an issue)
  • react-server Patch: Bug (non-breaking change which fixes an issue)
  • react-router Patch: Bug (non-breaking change which fixes an issue)
  • react-network Patch: Bug (non-breaking change which fixes an issue)
  • react-import-remote Patch: Bug (non-breaking change which fixes an issue)
  • react-html Patch: Bug (non-breaking change which fixes an issue)
  • react-hooks Patch: Bug (non-breaking change which fixes an issue)
  • react-graphql-universal-provider Patch: Bug (non-breaking change which fixes an issue)
  • react-form Patch: Bug (non-breaking change which fixes an issue)
  • react-bugsnag Patch: Bug (non-breaking change which fixes an issue)
  • react-async Patch: Bug (non-breaking change which fixes an issue)

Checklist

  • I have added a changelog entry, prefixed by the type of change noted above (Documentation fix and Test update does not need a changelog as we do not publish new version)

@peter-hamilton peter-hamilton requested a review from a team September 10, 2021 20:14
@peter-hamilton peter-hamilton marked this pull request as ready for review September 10, 2021 20:14
Copy link
Member

@BPScott BPScott left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking very nice! I've dropped a few comments inline asking about any usage

@@ -797,7 +797,7 @@ describe('useBaseList', () => {
</>
))}

<button type="button" onClick={onNewDefault} />
<button type="button" onClick={onNewDefault as any} />
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Having to cast this as any seems odd. How come it's needed? Is there a way we can change the signature of onNewDefault to make it compliant?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I chose the brute force cast because the test doesn't deal with MouseEvents and I wanted to minimize changes to the original test. I followed the example of clickEvent() and changeEvent() used throughout react-forms tests. I agree it seems wonky, but I'm not sure how to avoid it without replacing Variant[] values with fake React.MouseEvent objects.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Uuugh yeah, it seems that this is doing weird things - it's triggering a button onClick with an argument that is nothing to do with a MouseEvent I'm kinda surprised that this works at all. This shouldn't be using a button - is should be some custom Event type that gets triggered and then we can control the type rather than using something weird and not fit for purpose .

I guess this is fine for now - but at some point we should work out how to rework this to use a custom event rather than repurposing the onClick event

@@ -847,7 +847,7 @@ describe('useBaseList', () => {
optionName: newDefaultOption,
optionValue: newDefaultOptionValue,
},
]);
] as any);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Having to cast this as any seems odd. How come it's needed? Is there a way we can change the signature of newDefaultPrice/newDefaultOption/newDefaultOptionValue to make it compliant?

@@ -881,7 +881,7 @@ describe('useBaseList', () => {
optionName: newDefaultOption,
optionValue: newDefaultOptionValue,
},
]);
] as any);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Having to cast this as any seems odd. How come it's needed? Is there a way we can change the signature of newDefaultPrice/newDefaultOption/newDefaultOptionValue to make it compliant?

@@ -372,7 +374,7 @@ describe('useDynamicList', () => {
</>
))}

<button type="button" onClick={onNewDefault}>
<button type="button" onClick={onNewDefault as any}>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Having to cast this as any seems odd. How come it's needed? Is there a way we can change the signature of onNewDefault to make it compliant?

@@ -430,7 +432,7 @@ describe('useDynamicList', () => {
optionName: newDefaultOption,
optionValue: newDefaultOptionValue,
},
]);
] as any);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Having to cast this as any seems odd. How come it's needed? Is there a way we can change the signature of newDefaultPrice/newDefaultOption/newDefaultOptionValue to make it compliant?

packages/react-testing/src/tests/element.test.tsx Outdated Show resolved Hide resolved
Copy link
Member

@BPScott BPScott left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dropped a comment regarding the element test inline.

I'm happy to leave the react-form tests as is for now.

@peter-hamilton peter-hamilton merged commit dd41598 into main Sep 14, 2021
@peter-hamilton peter-hamilton deleted the add-test-typing branch September 14, 2021 17:06
@shopify-shipit shopify-shipit bot temporarily deployed to production September 14, 2021 20:47 Inactive
@shopify-shipit shopify-shipit bot temporarily deployed to gem November 16, 2021 02:42 Inactive
@shopify-shipit shopify-shipit bot temporarily deployed to michenly-beta November 25, 2021 02:39 Inactive
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants